<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="base.js" ></script>
<script type="text/javascript">
	var a = new Array(9,10,5,7,33,6,22,77,4,1);
	var i=0;
	function start(){
		quickSort(0,a.length-1);
		array.innerText=a;
		var data = 9;
		search.innerText ="要找的数据："+data;
		binarySearch(0,a.length-1,data);
	}
	
	function binarySearch(l,r,data){
		var midP = l+Math.floor((r-l)/2);
		search.innerText=search.innerText+"\n当前找的位置："+midP+"  次数:"+(++i);
		if(l >= midP){
			alert("没有此数据");
			return;
		}
		if(a[midP]>data){
			alert("找左边");
			binarySearch(l,midP,data);
		}else if(a[midP]<data){
			alert("找右边");
			binarySearch(midP,a.length-1,data);
		}else if(a[midP] == data){
			alert("找到"+a[midP]);
		}else{
			alert("没有找到");
		}
	}
	
</script>
</head>
<body onload="start()">
	<div id="array"></div>
	<div id="search"></div>
</body>
</html>